/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package core.threads;
import java.util.ArrayList;
import java.util.List;
import models.Card.Card;
import models.ListPlayer;
import models.Player;
import models.Role;
import models.Skill.Skill;
import myTest.MYTest;

/**
 *
 * @author Invince
 */
public class DataBase {
/*----------Attributs-------------------*/
    /**
     * 武将列表，游戏中用，主要通过id来寻找武将，注意这里是按id顺序排的
     */
    public static List<Role> dbRole=new ArrayList<Role>();//注意区别Server_Public_Data里的listRoleForSelection
//    public static final Object semaDBRole=new Object();
    /**
     * 卡片列表，游戏中用，主要通过id来寻找卡片，注意这里是按id顺序排的
     */
    public static List<Card> dbCard=new ArrayList<Card>();    
//    public static final Object semaDBCard=new Object();
    /**
     * Skill列表，游戏中用，主要通过id来寻找Skill，注意这里是按id顺序排的
     */
    public static List<Skill> dbSkill=new ArrayList<Skill>();
//    public static final Object semaDBSkill=new Object();
    /**
     * Player列表，游戏中用，主要通过id来寻找Player，注意这里是按id顺序排的
     * 新建游戏时把，game中的listPlayer复制过来，作为查询用
     */
    public static ListPlayer dbPlayer=new ListPlayer(0);//0表示id，这里不重要
//    public static final Object semaDBSkill=new Object();
/*----------Public functions------------*/
    public static Role findRoleByID(int id){
        if(id>DataBase.dbRole.size()){
            MYTest.println("Role not found,"+id+" out of range!");
            return null;
        }
        return DataBase.dbRole.get(id);
    }

    public static Skill findSkillByID(int id){
        if(id>DataBase.dbSkill.size()){
            MYTest.println("Skill not found,"+id+" out of range!");
            return null;
        }
        return DataBase.dbSkill.get(id);
    }

    public static Skill findSkillByName(String name){
        for(int i=0;i<DataBase.dbSkill.size();i++){
            if(DataBase.dbSkill.get(i).getName().equals(name)){
                return DataBase.dbSkill.get(i);
            }
        }
        return null;
    }

    public static Card findCardByID(int id){
        if(id>DataBase.dbCard.size()){
            MYTest.println("Card not found,"+id+" out of range!");
            return null;
        }
        return DataBase.dbCard.get(id);
    }

    public static Player findPlayerByID(int id){
        if(id>DataBase.dbPlayer.size()){
            MYTest.println("Role not found,"+id+" out of range!");
            return null;
        }
        return DataBase.dbPlayer.get(id);
    }
    
/*----------Private functions-----------*/
/*----------Constructor-----------------*/
/*----------Gets and sets---------------*/
}
